package torres.item.oneshot;

import java.util.ArrayList;
import java.util.List;

import torres.entity.Entity;
import torres.item.Item;
import torres.item.effect.Effect;

/**
 * @author Walter
 * An item that is always consumed on touch, even if it has no
 * effect on the usee.
 */
@SuppressWarnings("serial")
public class OneShotItem extends Item 
{
	List<Effect> effectList;
	
	/**
	 * Create a new OneShotItem with the specified name and no Effects.
	 * @param name The name of this OneShotItem.
	 */
	public OneShotItem(String name) {
		
		super.setConsumed(true);
		this.setName(name);
		this.setAsciiRep("S");
		this.setEffects(new ArrayList<Effect>());
	}
	
	/**
	 * Creates a new OneShotItem with the specified name and Effects.
	 * @param name The name of this OneShotItem.
	 * @param effects The Effects to be applied on touch.
	 */
	public OneShotItem(String name, List<Effect> effects) {
		
		this(name);
		this.setEffects(effects);
	}
	
	/**
	 * Creates a new OneShotItem that is a copy of the specified OneShotItem.
	 * @param item The OneShotItem to be copied.
	 */
	public OneShotItem(OneShotItem item) {
		this(item.getName(), item.getEffects());
	}
	
	/**
	 * Triggers the effect of an Entity walking on this item.
	 * @param e The Entity that is walking on this item
	 */
	public void onTouch(Entity e) {
		
		for(Effect o : this.getEffects())
			o.use(e);
	}
	
	
	/**
	 * Get the list of Effects that occur on touch.
	 * @return The list of Effects that occur on touch.
	 */
	private List<Effect> getEffects() {
		
		return this.effectList;
	}
	
	/**
	 * Set the list of Effects that occur on touch.
	 * @param effects The list of Effects to occur on touch.
	 */
	private void setEffects(List<Effect> effects) {
		
		this.effectList = effects;
	}
	
	/**
	 * Adds the specified Effect to this OneShotItem.
	 * @param effect The Effect to be added to this OneShotItem.
	 */
	public void addEffect(Effect effect) {
		
		effectList.add(effect);
	}

	/**
	 * Adds the specified Effects to this OneShotItem.
	 * @param effect The Effects to be added to this OneShotItem.
	 */
	public void appendEffectList(List<Effect> effectList)
	{
		this.effectList.addAll(effectList);
	}
}
